package com.appshelves;

import java.util.EnumMap;
import java.util.Map.Entry;

import android.app.Activity;

import com.appshelves.model.Model;
import com.appshelves.model.Model.Event;
import com.appshelves.model.Model.EventListener;

public abstract class EventListenerActivity extends Activity {

    EnumMap<Event, EventListener> listeners = new EnumMap<Event, EventListener>(Event.class);

    @Override
    protected void onResume() {
        super.onResume();
        addEventListeners();
    }

    @Override
    protected void onPause() {
        super.onPause();

        for (Entry<Event, EventListener> entry : listeners.entrySet())
            Model.removeListener(entry.getKey(), entry.getValue());
    }

    protected void addEventListener(Event event, EventListener listener) {
        listeners.put(event, listener);
        Model.addListener(event, listener);
    }

    protected abstract void addEventListeners();

}
